<template>
  <div class="container">
    <el-page-header @back="goBack" content="混凝土试块评定">
    </el-page-header>

    <div class="search">
      <span style="line-height: 100%">工程名称：</span>
      <el-input v-model="projectName" placeholder="请输入内容" style="width: 300px" />
      <span style="line-height: 100%; margin-left: 10px">单位工程：</span>
      <el-input v-model="subprojectName" placeholder="请输入内容" style="width: 300px" />
      <el-button type="primary" style="margin-left: 10px;margin-right: 10px" @click="search">搜索</el-button>
      <el-button type="warning" style="margin-left: 10px;margin-right: 10px;" @click="batchExport">批量导出</el-button>
    </div>

    <el-table :data="currentPageData" stripe style="width: 100%; margin-top: 15px"
      @selection-change="handleSelectionChange" row-key="taskId" ref="tableRef">
      <!-- 第一列：多选框 -->
      <el-table-column type="selection" width="55" :reserve-selection="true" />
      <!-- 第二列：编号 -->
      <el-table-column prop="projectCode" label="项目号" align="center" />
      <el-table-column prop="projectName" label="工程名称" align="center" />
      <el-table-column prop="subprojectName" label="单位工程名称" align="center" />
      <el-table-column prop="concreteStrength" label="混凝土强度等级" align="center" />
      <el-table-column prop="maintCondition" label="养护条件" align="center" />
      <el-table-column prop="stdPassDate" label="评定通过日期" align="center" />


      <!-- 最后一列：操作按钮 -->
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button type="primary" @click="handlePreview(scope.row)">
            预览
          </el-button>
          <el-button type="warning" @click="handleExport(scope.row)">
            导出
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 这是分页条  -->
    <el-pagination style="margin-top: 20px; text-align: center" :current-page="currentPage"
      :page-sizes="[1, 10, 15, 20]" :page-size="pageSize" layout="prev, pager, next, jumper,->,sizes,total"
      :total="totalData" @size-change="handleSizeChange" @current-change="handleCurrentChange" />

  </div>
</template>

<script>
import { searchShiKuaiPingDing } from '@/api/statementManage/hunNingTu/hunNingTu'

export default {
  data() {
    return {
      projectName: '',
      subprojectName: '',
      usePart: '',     //这三个用来搜素表格项
      currentPageData: [],  //当前页面数据
      currentPage: 1,
      pageSize: 10,
      totalData: 0,   //这三个是分页条数据
      selectedRows: []  //选中行数组
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    handleSizeChange(val) {
      this.pageSize = val
      console.log('表格容量更新为：' + val)
      this.search()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log('表格页数更新为：' + val)
      this.search()
    },
    handlePreview(row) {
      //预览报表
      this.previewData = row
      console.log(JSON.stringify(this.previewData)) // 看一下数据有没有传过来呢
      const localStorageId = 'table1' + Date.now() // 生成唯一ID用来本地存储data，因为这个东西需要传递
      localStorage.setItem(localStorageId, JSON.stringify(this.previewData)) // 把数据扔进localstorage
      this.$router.push({ path: '/report-viewer/concrete-ShiKuai', query: { localStorageId } })

    },
    handleExport(row) {
      console.log('导出表格行数据为：' + JSON.stringify(row))
    },
    handleSelectionChange(val) {
      this.selectedRows = val
      console.log('当前选中行为：' + JSON.stringify(val))
    },
    async search() {
      try {
        const { result } = await searchShiKuaiPingDing(this.currentPage, this.pageSize, this.subprojectName, this.projectName)
        this.currentPageData = result.records
        console.log(this.currentPageData)
        this.totalData = Number(result.total) // 给总记录数赋值，及时更改
        console.log('看到我说明表格数据接口成功请求了')
      } catch (e) {
        this.$message.error('获取报表数据失败！')
      }
    },
    batchExport() {
      console.log('进行了批量导出')
    }
  },
  mounted() {
    this.search()
  }
}
</script>

<style scoped>
.container {
  margin-top: 10px;
  margin-left: 10px;
}

.search {
  text-align: right;
  margin-top: 20px;
}
</style>
